﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using Soufun.DB;
using Soufun.Model;

namespace Soufun.DAL
{
    public class DProjectDetail
    {
        public int Add(ProjectDetailInfo model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("Insert into tprojectdetailinfo (");
            strSql.Append("ProjectId,BuildingID,UnitID,");
            strSql.Append("FloorID,HouseAttribute)");
            strSql.Append(" value (");
            strSql.Append("@0,@1,@2,");
            strSql.Append("@3,@4)");
            object[] paramaters = new object[]
                {
                    model.ProjectId,
                    model.BuildingID,
                    model.UnitID,
                    model.FloorID,
                    model.HouseAttribute 
                };
            int result = DbHelper.ExecuteSql(strSql.ToString(), paramaters);
             
            return result;
        }

        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();      
            strSql.Append("select t.Id,t.ProjectId,t.BuildingID,");
            strSql.Append("t.UnitID,t.FloorID,t.HouseAttribute,");
            strSql.Append("t.InsertTime,tb.ProjectName ");
            strSql.Append("from tprojectdetailinfo t ");
            strSql.Append("left join tprojecturlinfo tb on ");
            strSql.Append("t.ProjectId = tb.Id");            

            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }          
            return DbHelper.Query(strSql.ToString());
        }

        public DataSet GetInsetTimeList(int projectId)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select distinct InsertTime from tprojectdetailinfo ");
            strSql.Append(" where ProjectId =");
            strSql.Append(projectId);
            strSql.Append(" order by Id desc");
            return DbHelper.Query(strSql.ToString());
        }

        public DataSet GetAllInsetTimeList()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select distinct InsertTime from tprojectdetailinfo ");             
            strSql.Append(" order by Id desc");
            return DbHelper.Query(strSql.ToString());
        }

        public int DeleteByProjectId(int projectId)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from tprojectdetailinfo ");
            strSql.Append("where ProjectId=");
            strSql.Append(projectId);
            int result = DbHelper.ExecuteSql(strSql.ToString());
            return result;
        }

    }
}
